// 云函数：checkSelectedStock
const cloud = require('wx-server-sdk');
cloud.init();

exports.main = async (event, context) => {
  const db = cloud.database();
  const { openid, stockCode } = event;

  const selectedStock = await db.collection('selectedStock').where({ openid }).get();
console.log(selectedStock)
  if (selectedStock.data.length === 0) {
    return { isInSelectedStock: false };
  } else {
    const isInSelectedStock = selectedStock.data[0].stockCodes.includes(stockCode);
    console.log(selectedStock.data[0].stockCodes)
    console.log(stockCode)
    return { isInSelectedStock };
  }
};
